<?xml version='1.0' encoding='UTF-8' ?>

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                template="#{facesContext.externalContext.requestContextPath}../../resources/template/layout.xhtml">

    <ui:define name="content">

        <h:form id="frm" prependId="false">

            <p:growl id="grw" showDetail="true" sticky="false" life="3000" />

            <p:toolbar id="toolbar">

                <p:toolbarGroup align="left">
                    <h1 class="titulo">
                        Lista de Usuários
                    </h1>
                </p:toolbarGroup>

                <p:toolbarGroup align="right">

                    <p:ajaxStatus style="float: left; width:16px; height:16px; margin: 7px 7px 0px 0px;">  

                        <f:facet name="start">  
                            <h:graphicImage value="#{facesContext.externalContext.requestContextPath}../../resources/img/ajax.gif" />  
                        </f:facet>  

                        <f:facet name="complete">  
                            <h:outputText value="" />  
                        </f:facet>

                    </p:ajaxStatus>

                    <p:commandButton value="Novo" 
                                     image="ui-icon ui-icon-document"
                                     action="#{usuarioBean.prepararInserir()}"
                                     update="dtb"
                                     tabindex="1"
                                     style="width: 80px; margin-right: 5px;"/>

                    <p:commandButton value="Alterar"
                                     image="ui-icon ui-icon-pencil"
                                     action="#{usuarioBean.prepararAlterar()}"
                                     update="grw"
                                     tabindex="2"
                                     style="width: 80px; margin-right: 5px;" />

                    <p:commandButton value="Excluir"
                                     image="ui-icon ui-icon-trash"
                                     action="#{usuarioBean.prepararExcluir()}"
                                     update="msg"
                                     oncomplete="dlg.show()"
                                     tabindex="3"
                                     style="width: 80px; margin-right: 5px;"/>

                    <p:divider />

                    <p:commandButton id="btn-voltar"
                                     image="ui-icon ui-icon-arrowreturnthick-1-w"
                                     immediate="true"
                                     onclick="history.back()"
                                     action="#"
                                     title="Página Anterior"/>

                </p:toolbarGroup>

            </p:toolbar>

            <p:spacer height="15" />

            <p:dataTable id="dtb" 
                         value="#{usuarioBean.lista}"
                         var="usuario"
                         selectionMode="single"
                         selection="#{usuarioBean.selecionado}"
                         paginator="true"
                         paginatorPosition="bottom"
                         rows="10"
                         emptyMessage="Nenhum registro encontrado">

                <p:column sortBy="#{usuario.id}" style="width: 1%;">
                    <f:facet name="header">
                        <h:outputText value="#" />
                    </f:facet>
                    <h:outputText value="#{usuario.id}" />
                </p:column>

                <p:column sortBy="#{usuario.login}" style="width: 1%;">
                    <f:facet name="header">
                        <h:outputText value="Usuário" />
                    </f:facet>
                    <h:outputText value="#{usuario.login}" />
                </p:column>

                <p:column sortBy="#{usuario.nome}">
                    <f:facet name="header">
                        <h:outputText value="Nome" />
                    </f:facet>
                    <h:outputText value="#{usuario.nome}" />
                </p:column>

                <p:column sortBy="#{usuario.tipo.label}">
                    <f:facet name="header">
                        <h:outputText value="Tipo" />
                    </f:facet>
                    <h:outputText value="#{usuario.tipo.label}" />
                </p:column>

            </p:dataTable>

            <!-- Dialog Excluir -->
            <p:dialog widgetVar="dlg"
                      id="dlg"
                      width="380"
                      header="Excluir Registro"
                      showEffect="explode" 
                      hideEffect="explode"
                      resizable="false"
                      modal="true">

                <p:messages id="msg" showDetail="true" />

                <p:commandButton value="Sim" 
                                 image="ui-icon ui-icon-circle-check"
                                 actionListener="#{usuarioBean.excluir()}"
                                 oncomplete="dlg.hide()"
                                 update="dtb grw"
                                 style="width: 70px;" />

                <p:spacer width="10" />

                <p:commandButton value="Não"
                                 image="ui-icon ui-icon-circle-close"
                                 oncomplete="dlg.hide()" 
                                 style="width: 70px;" />
            </p:dialog>

        </h:form>

    </ui:define>

</ui:composition>
